//维修统计
<template>
  <div class="tenantMenu_main main_container">
    <div class="main_header">
      <div class="padding_container">
        <div class="left"><Breadcrumb /></div>
        <div class="right">
          <HeaderOperation :parent="this" />
        </div>
      </div>
    </div>
    <div v-loading="loading" class="main_main">
      <search-bar-new :parent="this" />
      <div ref="table_container" class="table_container">
        <el-table
          ref="table"
          :data="tableData"
          stripe
          border
          :height="tableHeight"

          :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
          show-summary
          :summary-method="getSummaries"
          :header-cell-class-name="cellClassName"
          @sort-change="(column)=>{sortChange(column, this)}"
          @selection-change="(val)=>{selectionChange(val, this)}"
        >
          <el-table-column type="selection" align="center" width="70" />
          <el-table-column
            prop="deviceInfo"
            label="设备信息"
            min-width="200"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            prop="deviceModel"
            label="规格型号"
            min-width="100"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            prop="deviceLocation"
            label="设备位置"
            min-width="120"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="停机统计"
          >
            <el-table-column
              prop="runDuration"
              label="运行时长(h)"
              :min-width="SETTINGS.settings_decimalDigits_length"
            />
            <el-table-column
              prop="haltDuration"
              label="停机时长(h)"
              :min-width="SETTINGS.settings_decimalDigits_length"
            />
            <el-table-column
              prop="haltProbability"
              label="停机率(%)"
              :min-width="SETTINGS.settings_decimalDigits_length"
            />
          </el-table-column>
          <el-table-column
            label="维修统计"
          >
            <el-table-column
              prop="repairTimes"
              label="维修次数"
            />
            <el-table-column
              prop="repairDuration"
              label="维修时长(h)"
              :min-width="SETTINGS.settings_decimalDigits_length"
            />
            <el-table-column
              prop="repairPaysThousandths"
              label="维修费用(元)"
              :min-width="SETTINGS.settings_decimalDigits_length"
            />
          </el-table-column>
          <el-table-column
            label="MTTR/MTBF(小时/次)"
            :min-width="SETTINGS.settings_decimalDigits_length"
          >
            <el-table-column
              prop="mttr"
              label="MTTR(平均修理时间)"
              :min-width="SETTINGS.settings_decimalDigits_length"
            />
            <el-table-column
              prop="mtbf"
              label="MTBF(平均故障间隙)"
              :min-width="SETTINGS.settings_decimalDigits_length"
            />
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="main_bottom">
      <pagination
        :total="total"
        :page.sync="pageData.pageNum"
        :limit.sync="pageData.pageSize"
        :selected-num="selectionsAll.length"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import { list } from '@/api/equipmentManage/equipmentReport/serviceReport'
import { getEquipmentList1 } from '@/api/equipmentManage/baseInfo/equipmentInfo'
import { getBlob } from '@/utils/util'
export default {
  name: 'Index',
  data() {
    return {
      loading: true,
      pageId: '设备维修统计', // 页面唯一标识
      pageData: {
        pageNum: 1,
        pageSize: 20,
        orderByColumn: 'updateTime',
        isAsc: 'desc'
      },
      isManyhead: true,
      total: 1, // 数据一共有多少条
      mainId: 'id', // 表格行ID
      tableHeight: '0', // 表格高度
      tableData: [], // 表格数据
      tableColumns: [], // 表格实际用的字段
      searchColumns: [], // 搜索区实际用的字段
      selections: [], // 表格当前页所选中的行
      selectionsAll: [], // 表格所有页选中的行
      defaultSearchColumns: [// 搜索区常规字段（初始值）
        { prop: 'searchValue', label: '模糊搜索', type: 'input' },
        { prop: 'bookId', label: '设备信息', type: 'select', optionsName: 'equipmentList1' },
        // { prop: 'deviceModel', label: '规格型号', type: 'input' },
        // { prop: 'deviceLocation', label: '设备位置', type: 'input' },
        { prop: 'searchTime', label: '统计时间', type: 'time', hasDefault: true, defaultKey: 'defaultSearchTime' }
      ],
      multiHeader: [
        ['设备信息', '规格型号', '设备位置', '停机统计', '', '', '维修统计', '', '', 'MTTR/MTBF(小时/次)', '']
      ],
      header: [
        '', '', '', '运行时长(h)', '停机时长(h)', '停机率(%)', '维修次数', '维修时长(h)', '维修费用(元)', 'MTTR(平均修理时间)', 'MTBF(平均故障间隙)'
      ],
      keyWord: [
        'deviceInfo', 'deviceModel', 'deviceLocation', 'runDuration', 'haltDuration', 'haltProbability', 'repairTimes', 'repairDuration', 'repairPays', 'mttr', 'mtbf'
      ],
      merges: [
        'A1:A2', 'B1:B2', 'C1:C2', 'D1:F1', 'G1:I1', 'J1:K1'
      ],
      headerStyle: [
        'A1', 'B1', 'C1', 'D1', 'E1', 'F1', 'G1', 'H1', 'I1', 'J1', 'K1'
      ],
      defaultTableColumns: [
        { prop: 'createTime', label: '创建时间', canOrder: false },
        { prop: 'updateTime', label: '更新时间', canOrder: false }
      ],
      operationData: [ // 右上角的操作按钮
        { label: '批量导出', perm: '' },
        { label: '页面配置', perm: '' }
      ],
      statusOptions2: [ // 选择组件数据源
        { value: undefined, label: '全部' },
        { value: 141, label: '白班' },
        { value: 142, label: '夜班' }
      ],
      equipmentList: [],
      statusOptionsWarehouse: [],
      equipmentList1: [],
      defaultSearchTime: [],
      Updata: []
    }
  },
  created() {
    this.defaultSearchTime = [this.$moment(new Date()).subtract(1, 'months').format('YYYY-MM-DD') + ' 00:00',
      this.$moment(new Date()).format('YYYY-MM-DD') + ' 23:59']
  },
  mounted() {
    this.loadEquipmentList()
  },
  methods: {
    getList() {
      list(this.pageData).then(res => {
        this.tableData = res.data.dataTable.data
        this.total = res.data.dataTable.total
        this.Updata = res.data.total
        this.loading = false
        this.$nextTick(() => {
          this.setSelectRow(this)// 设置行选中
          this.tableHeight = this.$refs.table_container.offsetHeight
        })
      })
    },
    loadEquipmentList() {
      getEquipmentList1().then(res => {
        res.data.forEach(item => {
          item['value'] = item.id
          item['label'] = item.deviceName
        })
        this.equipmentList1 = res.data
      })
    },
    getExportData(data) {
      // return list(data)
      return getBlob('/device/repair/statistic/repairStatisticList/export', data, 'post')
    },
    // 合计行
    getSummaries(param) {
      const {
        columns
      } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index == 0) {
          sums[index] = '合计'
          return
        }
        switch (column.property) {
          case 'runDuration':
            sums[index] = this.Updata.runDuration
            break
        }
        switch (column.property) {
          case 'haltDuration':
            sums[index] = this.Updata.haltDuration
            break
        }
        switch (column.property) {
          case 'haltProbability':
            sums[index] = this.Updata.haltProbability + '%'
            break
        }
        switch (column.repairTimes) {
          case 'repairTimes':
            sums[index] = this.Updata.repairTimes
            break
        }
        switch (column.property) {
          case 'repairDuration':
            sums[index] = this.Updata.repairDuration
            break
        }
        switch (column.property) {
          case 'repairPays':
            sums[index] = this.Updata.repairPays
            break
        }
        switch (column.property) {
          case 'mttr':
            sums[index] = this.Updata.mttr
            break
        }
        switch (column.property) {
          case 'mtbf':
            sums[index] = this.Updata.mtbf
            break
        }
        switch (column.property) {
          case 'repairTimes':
            sums[index] = this.Updata.repairTimes
            break
        }
      })
      return sums
    },
    cellClassName(data) {
      if (data.column.label == '停机统计' || data.column.label == '维修统计' || data.column.label == 'MTTR/MTBF(小时/次)') {
        return 'center'
      }
    }
  }
}
</script>

<style lang="less" scoped>
/deep/ .el-table thead.is-group th.el-table__cell{
      background-color: transparent!important;
}
/deep/ .el-table__footer-wrapper tbody td.el-table__cell{
  background-color: rgba(0,0,0,0);
}
/deep/ .el-table__footer-wrapper tbody td.el-table__cell{
  background-color: transparent!important;
}
/deep/ .el-table th.el-table__cell.is-leaf, .el-table td.el-table__cell {
  border-bottom: 1px solid #dfe6ec;
}

/deep/ .el-table__header-wrapper .center .cell{
  justify-content: center !important;
}
/deep/ .el-table__header-wrapper{
  .el-table__cell{
    border-right: 1px solid #dfe6ec !important;
  }
  tr:nth-child(2){
    .el-table__cell{
      border-top: 1px solid #dfe6ec !important;
    }
  }
}
</style>
